﻿using System;
using System.Linq.Expressions;

namespace SemanticEx
{
	public static class ExpressionExtensions
	{
		public static UnaryExpression Convert(this Expression @this, Type type)
		{
			return Expression.Convert(@this, type);
		}

		public static UnaryExpression Convert<T>(this Expression @this)
		{
			return @this.Convert(typeof(T));
		}

		public static ConstantExpression ToConstant<T>(this T @this)
		{
			return Expression.Constant(@this, typeof(T));
		}

		public static MethodCallExpression ChangeType(this Expression @this, Type type)
		{
			return ExpressionEx.Call(typeof(Convert), "ChangeType", @this.Convert<object>(), type.ToConstant());
		}

		public static MethodCallExpression ChangeType<T>(this Expression @this)
		{
			return @this.ChangeType(typeof(T));
		}

		public static LambdaExpression Lambda(this Expression @this, params ParameterExpression[] parameters)
		{
			return Expression.Lambda(@this, parameters);
		}

		public static Expression<Func<T, TResult>> Lambda<T, TResult>(this Expression @this, ParameterExpression parameter)
		{
			return Expression.Lambda<Func<T, TResult>>(@this, parameter);
		}

		public static ConditionalExpression Condition(this Expression @this, Expression ifTrue, Expression ifFalse)
		{
			return Expression.Condition(@this, ifTrue, ifFalse);
		}

		public static DynamicExpression Power(this Expression @this, Expression right)
		{
			return ExpressionEx.Power(@this, right);
		}

		public static DynamicExpression And(this Expression @this, Expression right)
		{
			return ExpressionEx.And(@this, right);
		}

		public static DynamicExpression Or(this Expression @this, Expression right)
		{
			return ExpressionEx.Or(@this, right);
		}

		public static DynamicExpression Equal(this Expression @this, Expression right)
		{
			return ExpressionEx.Equal(@this, right);
		}

		public static DynamicExpression NotEqual(this Expression @this, Expression right)
		{
			return ExpressionEx.NotEqual(@this, right);
		}

		public static DynamicExpression GreaterThanOrEqual(this Expression @this, Expression right)
		{
			return ExpressionEx.GreaterThanOrEqual(@this, right);
		}

		public static DynamicExpression LessThanOrEqual(this Expression @this, Expression right)
		{
			return ExpressionEx.LessThanOrEqual(@this, right);
		}

		public static DynamicExpression GreaterThan(this Expression @this, Expression right)
		{
			return ExpressionEx.GreaterThan(@this, right);
		}

		public static DynamicExpression LessThan(this Expression @this, Expression right)
		{
			return ExpressionEx.LessThan(@this, right);
		}

		public static DynamicExpression Add(this Expression @this, Expression right)
		{
			return ExpressionEx.Add(@this, right);
		}

		public static DynamicExpression Subtract(this Expression @this, Expression right)
		{
			return ExpressionEx.Subtract(@this, right);
		}

		public static DynamicExpression Multiply(this Expression @this, Expression right)
		{
			return ExpressionEx.Multiply(@this, right);
		}

		public static DynamicExpression Divide(this Expression @this, Expression right)
		{
			return ExpressionEx.Divide(@this, right);
		}

		public static DynamicExpression Not(this Expression @this)
		{
			return ExpressionEx.Not(@this);
		}

		public static DynamicExpression Negate(this Expression @this)
		{
			return ExpressionEx.Negate(@this);
		}
	}
}